package com.hulman.oms.web;

import com.hulman.oms.bean.Result;
import com.hulman.oms.bean.OnlyOffice;
import com.hulman.oms.service.OnlyOfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: maxwellens
 */
@RestController
public class OnlyOfficeController
{
	@Autowired
	private OnlyOfficeService onlyOfficeService;

	@GetMapping("/only-offices/{id}")
	public Result findOnlyOfficeById(@PathVariable Integer id)
	{
		OnlyOffice onlyOffice = onlyOfficeService.findOnlyOfficeById(id);
		return new Result(onlyOffice);
	}

	@GetMapping("/only-offices")
	public Result findOnlyOffices(Integer page, Integer limit, String fileId, String fileName)
	{
		Map<String, Object> map = new HashMap<>();
		map.put("page", page);
		map.put("limit", limit);
        map.put("fileId", fileId);
        map.put("fileName", fileName);
		return onlyOfficeService.findOnlyOfficesResult(map);
	}

	@DeleteMapping("/only-offices/{id}")
	public Result deleteOnlyOfficeById(@PathVariable Integer id)
	{
		onlyOfficeService.deleteOnlyOfficeById(id);
		return Result.SUCCESS;
	}

	@PutMapping("/only-offices")
	public Result saveOnlyOffice(OnlyOffice onlyOffice)
	{
		onlyOfficeService.saveOnlyOffice(onlyOffice);
		return Result.SUCCESS;
	}

}
